<template>
  <div class="out-warehouse-receipt-page">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle"></super-search>
    </div>
    <div class="content-wrapper">
      <a-tabs v-model:activeKey="activeKey" @change="changeTabHandle">
        <a-tab-pane key="1" :tab="`未配置司机(${pageStat['1']})`"></a-tab-pane>
        <a-tab-pane key="2" :tab="`未交货(${pageStat['2']})`"></a-tab-pane>
        <a-tab-pane key="3" :tab="`已交货(${pageStat['3']})`"></a-tab-pane>
      </a-tabs>
      <super-table
        :height="tableHeight"
        ref="tableRef"
        :activeKey="activeKey"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :data="tableData"
        :total="searchForm.total"
        :column="tableColumn"
        @change-page="getData"
      >
        <template #tool>
          <a-button type="primary" v-if="activeKey === '2'" @click="deliveryHandle">交货</a-button>
          <a-button type="primary" v-if="activeKey === '1'" @click="setDriverHandle">批量配置</a-button>
        </template>
        <template #action="{ row }">
          <a-button type="link" v-debounce @click="detailsHandle(row)"> 查看详情</a-button>
          <a-button type="link" v-debounce @click="driverHandle(row)" v-if="activeKey === '1'">配置司机</a-button>
          <a-button type="link" v-debounce v-if="activeKey !== '1'" @click="downLoadOutWarehouseReceipt(row)">下载出仓单</a-button>
        </template>
      </super-table>
    </div>
    <!-- 抽屉 -->
    <a-drawer
      class="custom-drawer"
      v-model:visible="drawerOpts.visible"
      :title="drawerOpts.title"
      :maskClosable="false"
      :closable="true"
      @close="searchHandle"
      :width="drawerOpts.width"
      placement="right"
    >
      <component
        v-model:visible="drawerOpts.visible"
        :is="drawerOpts.component"
        :activeKey="activeKey"
        :type="drawerOpts.type"
        :pass-data="drawerOpts.passData"
        @submit="drawerSubmitHandle"
      ></component>
    </a-drawer>

    <!-- 弹窗 -->
    <a-modal v-model:visible="dialogOpts.visible" :maskClosable="false" :keyboard="false" :closable="false" :footer="null" :title="dialogOpts.title" :width="dialogOpts.width">
      <component v-model:visible="dialogOpts.visible" :is="dialogOpts.component" :type="dialogOpts.type" :pass-data="dialogOpts.passData" @submit="dialogSubmitHandle"></component>
    </a-modal>
  </div>
</template>
<script lang="ts">
import Details from "./components/details/index.vue";
import SetDirver from "./components/setDriver/index.vue";
export default {
  name: "OutWarehouseReceipt",
  components: {
    Details,
    SetDirver
  }
};
</script>
<script setup lang="ts">
import InitHook from "./composables/initHook";
import TableHeightHook from "@/hook/tableHeightHook";
import { searchItemList } from "./data";
import OperationHook from "./composables/operationHook";
import CommonHook from "@/hook/commonHook";
import ModalHook from "@/hook/modalHook";

const { tableHeight, loading } = TableHeightHook(50);
const { tableData, searchForm, tableRef, drawerOpts, activeKey, pageStat, dialogOpts } = InitHook();
const { downloadFileByUrl } = CommonHook();
const { searchHandle, getData, changeTabHandle, tableColumn, deliveryHandle, detailsHandle, driverHandle, downLoadOutWarehouseReceipt, setDriverHandle } = OperationHook({
  searchForm,
  loading,
  tableData,
  tableRef,
  downloadFileByUrl,
  activeKey,
  pageStat,
  drawerOpts,
  dialogOpts
});
searchHandle();
const { drawerSubmitHandle, dialogSubmitHandle } = ModalHook({
  drawerOpts,
  dialogOpts,
  callBack: () => searchHandle()
});
</script>
<style lang="stylus" scoped></style>
